package com.authenticateCenter.service.impl;

import com.authenticateCenter.domain.entity.Authority;
import com.authenticateCenter.domain.entity.RoleAuthority;
import com.authenticateCenter.mapper.AuthorityMapper;
import com.authenticateCenter.service.IAuthorityService;
import com.authenticateCenter.service.IRoleAuthorityService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.common.mybaits.CustomPage;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 大忽悠
 * @since 2022年10月08日
 */
@Service
@RequiredArgsConstructor
@Transactional
public class AuthorityServiceImpl extends ServiceImpl<AuthorityMapper, Authority> implements IAuthorityService {
    private final AuthorityMapper authorityMapper;

    @Override
    public List<Authority> getAuthoritysByRid(Integer rId, CustomPage customPage) {
        if(!CustomPage.enable(customPage)){
            return authorityMapper.getAuthoritysByRid(rId);
        }
        return authorityMapper.getAuthoritysByRidWithPage(rId,customPage);
    }

    @Override
    public void removeAuthority(Integer authorityId, IRoleAuthorityService iRoleAuthorityService) {
        removeById(authorityId);
        iRoleAuthorityService.remove(new QueryWrapper<RoleAuthority>().eq("aid",authorityId));
    }

}
